// pages/login/login.js
var app = getApp;
const router = require('../../config').router

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  //联络员账号
  contactName:function(e) {
    this.setData({
      contactName: e.detail.value
    })
  },
  //联络员密码
  contactPassword:function(e) {
    this.setData({
      contactPassword: e.detail.value
    })
  },
  getUserInfo: function () {
    var that = this;
    var contactName = that.data.contactName
    if (contactName == '') {
      wx.showModal({
        title: '提示',
        content: '请填写联络员账号！',
        success: function (res) { }
      })
      return
    }
    var contactPassword = that.data.contactPassword
    if (contactPassword == '') {
      wx.showModal({
        title: '提示',
        content: '请填写联络员密码！',
        success: function (res) { }
      })
      return
    }
    wx.getUserInfo({
      // lang: 'zh_CN',
      success: function (res) {
        wx.setStorageSync('userinfo', res.userInfo)
        wx.request({
          url: router,
          data: {
            appKey: 'w4q897jgvxkb',
            method: 'contact.user.login',
            v: '1.0',
            format: 'json',
            loginName:contactName,
            password:contactPassword,
          },
          success: function (res) {
            if (res.statusCode == 200 && res.data.error != 'error') {
              console.log(res.data)
              if (res.data.code == 200){
                wx.setStorageSync('contactName1', contactName)
                wx.setStorageSync('contactPassword1', contactPassword)
                wx.navigateTo({
                  url: '/pages/personal/submitted/submitted'
                })
              }else{
                wx.showModal({
                  title: '提示',
                  content: '账号或密码错误！',
                  success: function (res) { }
                })
              }
            }
          }
        });
      },
      fail: function (res) {
        console.log(res)
      }
    })
  }
})